package designer.single;

/**
 * 推荐的同步方式
 * 有两种,第一种是
 * Created by tanlee on 2016/4/6.
 */
public class SingletonBest {

    private static SingletonBest singletonBest;

    private SingletonBest() {
    }

    public static SingletonBest getInstance(){
        try{
            if (singletonBest == null){
                Thread.sleep(3000);
                synchronized (SingletonBest.class){
                    if (singletonBest == null){
                        singletonBest = new SingletonBest();
                    }
                }
            }
        }
        catch (InterruptedException e){
            e.printStackTrace();
        }
        return  singletonBest;
    }
}
